<?php
include("../../tools/session.php");
include("../../tools/controls.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
$page_status = $_POST["page_status"];
// $page_status = $_GET["page_status"];
$per_page = 10;
   
// 如果 $page_status 为空，那么显示页面
if (!$page_status)
{
   include("../../tools/mysql.php");
   db_connect();
   
   include("tpl-inc-wp.php");
   
   // $sql = "SELECT ceil(count(archive_id)/" . $per_page . ") num FROM archive";
   $sql = "SELECT count(archive_id) num FROM archive";
   $re = db_query_once($sql);

   // $tpl->assign("page_num", $re["num"]);
   $tpl->assign("wholepage", $re["num"]);
   $tpl->display($oa_tpl_path . "/default/address_list.html");
}
// 如果 $page_status 为 1,那么生成数据 XML
elseif ($page_status == 1)
{
   include("../../tools/mysql.php");
   db_connect();
   
   $page = $_POST["page"];
   // $page = $_GET["page"];
   $page = ($page == "" || $page <= 0) ? 1 : $page;
   
   header("content-type: text/xml");
   echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   echo "<address_list>\n";
   
   $sql = "SELECT archive_id, username, sex, tel, phone FROM archive ORDER BY archive_id ASC ";
   $re = db_query_page($sql, $page, $per_page);
   
   foreach($re as $v)
	 {
		echo "<item>\n";
		echo "<archiveid>" . $v["archive_id"] . "</archiveid>\n";
		echo "<username><![CDATA[" . $v["username"] . "]]></username>\n";
		echo "<sex>" . $v["sex"] . "</sex>\n";
		echo "<tel><![CDATA[" . $v["tel"] . "]]></tel>\n";
		echo "<phone><![CDATA[" . $v["phone"] . "]]></phone>\n";
		echo "</item>\n";
	 }
   
   echo "</address_list>\n";
}
// 如果 $page_status 为 2,那么单人数据 XML
elseif ($page_status == 2)
{
   $id = $_POST["id"];
   
   include("../../tools/mysql.php");
   db_connect();
   
   $page = $_POST["page"];
   // $page = $_GET["page"];
   $page = ($page == "" || $page <= 0) ? 1 : $page;
   
   header("content-type: text/xml");
   echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   echo "<address_list>\n";
   
   $sql = "SELECT username, sex, tel, phone, qq, email, address, photo "
	 . " FROM archive WHERE archive_id=" . $id . " ORDER BY archive_id ASC ";
   $re = db_query_once($sql, $page, $per_page);
   
   echo "<username><![CDATA[" . $re["username"] . "]]></username>\n";
   echo "<sex>" . $re["sex"] . "</sex>\n";
   echo "<tel><![CDATA[" . $re["tel"] . "]]></tel>\n";
   echo "<phone><![CDATA[" . $re["phone"] . "]]></phone>\n";
   echo "<qq><![CDATA[" . $re["qq"] . "]]></qq>\n";
   echo "<email><![CDATA[" . $re["email"] . "]]></email>\n";
   echo "<address><![CDATA[" . $re["address"] . "]]></address>\n";
   echo "<photo><![CDATA[" . $re["photo"] . "]]></photo>\n";
   
   echo "</address_list>\n";
}
   
?>
